import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueRouter from 'vue-router'
import Vuex from 'vuex'
import store from './vuex/store'
import 'default-passive-events'
import userDiction from './common/js/diction'
import routes from './routes'
import 'font-awesome/css/font-awesome.min.css'
import elTableInfiniteScroll from 'el-table-infinite-scroll';

Vue.use(elTableInfiniteScroll);
import axios from 'axios'
import moment from 'moment'
Vue.prototype.moment  =  moment; 
import QRCode from 'qrcodejs2'
Vue.prototype.QRCode  =  QRCode; 
Vue.filter('formatDate', (input, formatString = "YYYY-MM-DD HH:mm:ss") => {
  if(!input){
    return '-'
  }
      //es5函数参数设置默认值
      //const lastFormatString = formatString || ''
      // moment(input) 把时间字符串转成时间对象
      // format(formatString) 把时间对象，按照指定格式，格式化成符合条件的字符串
      return moment(input).format(formatString)
  
  })

  
Vue.prototype.$http = axios

 
Vue.prototype.diction = sessionStorage.getItem('bospower')
Vue.prototype.million = 100000000
Vue.prototype.jurisdictions = userDiction
// Vue.prototype.loading = true



import i18n from './common/i18n/index'
import md5 from 'js-md5';
Vue.prototype.$md5 = md5;
Vue.use(ElementUI)

// import mixin from'./components/js/mixin.js'
// Vue.mixin(mixin)






  // 调用vuex actoin
  store.dispatch("getsdecimallength");

  










Vue.use(VueRouter)
Vue.use(Vuex)
// Vue.use(lrz)

import XLSX from 'xlsx'
Vue.prototype.XLSX = XLSX

const router = new VueRouter({
  // mode:'history',
  routes
})


router.beforeEach((to, from, next) => {
  if(from.path == '/404'){
    window.history.back(-1)
  }
  if (to.path == '/login') {
    sessionStorage.removeItem('boxToken');
    sessionStorage.removeItem('bospower');
  }
  let bospower = sessionStorage.getItem('bospower')
  let boxToken = sessionStorage.getItem('boxToken')
  if (!boxToken && to.path != '/login') {
        next({ path: '/login' })
  } else {
     if(to.path=='/login'){
          next()  
      }else if(userDiction['jurisdiction'][bospower].indexOf(to.path)>=0){
        next();
      }
      else {
        next({path:'/404'});
      } 
    }
  
})

Vue.prototype.$axios = axios
window.onbeforeunload = function (e) {
  // var message = 'some word';
  // e = e || window.event;
  // if (e) {
  //     e.returnValue = message;
  // }
  // return "浏览器关闭！";
};




new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  i18n,
  //components: { App }
  render: h => h(App)
}).$mount('#app')
